<#if ((parameters.validate?default(false) == true) && (parameters.performValidation?default(false) == true))>

    <script type="text/javascript">
        function validateForm_${parameters.id}() {
            var form = document.getElementById("${parameters.id}");
            clearErrorMessages();
            var errors = false;
            var continueValidation = true;
            <#list parameters.tagNames as tagName >
                <#list tag.getValidators("${tagName}") as validator >
                    // field name: ${validator.fieldName}
                    // validator name: ${validator.validatorType}
                    if (form.elements['${validator.fieldName}']) {
                        var field = form.elements['${validator.fieldName}'];
                        var error = "${validator.getMessage(action)?js_string}";
                        <#if validator.validatorType = "required">
                            if(!validateForm_required(field)){
                                addError(field, error);
                                errors = true;
                                <#if validator.shortCircuit > continueValidation = false;</#if>
                            }
                        <#elseif validator.validatorType = "int">
                            if(!validateForm_int(field)){
                                addError(field, error);
                                errors = true;
                                <#if validator.shortCircuit > continueValidation = false;</#if>
                            }
                        <#elseif validator.validatorType = "number">
                            if(!validateForm_number(field)){
                                addError(field, error);
                                errors = true;
                                <#if validator.shortCircuit > continueValidation = false;</#if>
                            }
                        <#elseif validator.validatorType = "date">
                            if(!validateForm_date(field)){
                                addError(field, error);
                                errors = true;
                                <#if validator.shortCircuit > continueValidation = false;</#if>
                            }
                        <#elseif validator.validatorType = "email">
                            if(!validateForm_email(field)){
                                addError(field, error);
                                errors = true;
                                <#if validator.shortCircuit > continueValidation = false;</#if>
                            }
                        <#elseif validator.validatorType = "stringLength">
                            // min length: ${validator.min}
                            // max length: ${validator.max}
                            if(!validateForm_stringLength(field,${validator.min},${validator.max})){
                                addError(field, error);
                                errors = true;
                                <#if validator.shortCircuit > continueValidation = false;</#if>
                            }
                        <#elseif validator.validatorType = "numberRange">
                            if(!validateForm_numberRange(field,${validator.min},${validator.max})){
                                addError(field, error);
                                errors = true;
                                <#if validator.shortCircuit > continueValidation = false;</#if>
                            }
                        <#elseif validator.validatorType = "money">
                            if(!validateForm_money(field)){
                                addError(field, error);
                                errors = true;
                                <#if validator.shortCircuit > continueValidation = false;</#if>
                            }
                        </#if>
                    }
                </#list>
            </#list>
            return !errors;
        }
    </script>
</#if>